/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.comfacauca.xmlc2.servlet;

import com.comfacauca.xmlc2.dao.ProyectosDAO;
import com.comfacauca.xmlc2.entidades.Avance;
import com.comfacauca.xmlc2.entidades.RequerimientosVw;
import com.comfacauca.xmlc2.servicio.ProyectosI;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author sarita
 */
public class AvanceGraficaServlet extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    
    ProyectosI proyectosI = new ProyectosDAO();
    private List lista;
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
       
        
//        String data = "Categories,01/07/2014,02/07/2014,03/07/2014,04/07/2014,05/07/2014,06/07/2014,07/07/2014\n" +
//                        "SUBSI-01,8,4,6,5,3,4,1\n" +
//                        "SUBSI-02,3,46,2,36,66,84,93\n" +
//                        "SUBSI-03,3,64,62,3,6,4,3\n" +
//                        "SUBSI-05,3,45,2,3,6,4,3\n" +
//                        "SERVI-12,3,54,2,3,6,4,3\n" +
//                        "SUBSI-32,3,4,2,3,6,4,3\n" +
//                        "SERVI-33,86,76,79,77,3,4,6\n" +
//                        "XML-44,3,16,13,15,34,23,1";
        
        String fecha = request.getParameter("fecha_avance");
        
        HttpSession session = request.getSession();
        Integer idresp = (Integer) session.getAttribute("id");
        lista = proyectosI.getItemsUsuario(idresp);      
        
       
        String data = "Categories,"+fecha+"\\n" ;
        
        for (RequerimientosVw m : (List<RequerimientosVw>) lista) {
            Object obj = proyectosI.traerAvance(m.getId());
            
            data +=  "\""+m.getCodigo()+","+obj+"\"\n" ;
            
        }               
       
        out.println(data);
        
        
        
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
